package my.edu.model.information.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import my.edu.common.validate.groups.Insert;
import my.edu.common.domain.Response;
import my.edu.model.information.entity.dto.CustomerCategoryDTO;
import my.edu.model.information.service.ICustomerCategoryService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/info/customerCategory")
@RestController
@Tag(name = "客户类别接口")
@Validated
public class CustomerCategoryController {

    @Autowired
    private ICustomerCategoryService customerCategoryService;

    @PutMapping
    @RequiresPermissions("customer:save")
    @Operation(summary = "新增客户类别")
    public Response saveCategory(@Validated(value = Insert.class) @RequestBody CustomerCategoryDTO customerCategoryDTO) {
        customerCategoryService.savenew(customerCategoryDTO);
        return Response.success();
    }

    @GetMapping("/list")
    @RequiresPermissions("customer:get")
    @Operation(summary = "获取客户类别列表")
    public Response getCategoryList() {
        return Response.success(customerCategoryService.listAll());
    }

    @PostMapping
    @RequiresPermissions("customer:update")
    @Operation(summary = "修改客户类别")
    public Response updateCategory(@Valid @RequestBody CustomerCategoryDTO customerCategoryDTO) {
        customerCategoryService.updateByDTO(customerCategoryDTO);
        return Response.success();
    }

    @GetMapping("/{id}")
    @RequiresPermissions("customer:get")
    @Operation(summary = "根据编号获取客户类别信息")
    public Response getAccountById(@PathVariable @NotBlank(message = "id不能为空") String id) {
        return Response.success(customerCategoryService.getById(id));
    }

}
